package com.shujia

import scala.io.{BufferedSource, Source}

object Demo18Stu {
  def main(args: Array[String]): Unit = {

    //出学生表中所有文科一班的学生，只保留学号和姓名班级

    //读取数据
    val source: BufferedSource = Source.fromFile("scala/data/students.csv")
    val students: List[String] = source.getLines().toList

    //取出文科一班的学生
    val filterList: List[String] = students.filter((stu: String) => {
      val clazz: String = stu.split(",")(4)
      "文科一班".equals(clazz)
    })

    //只保留学号和姓名班级
    val stuList: List[String] = filterList.map((stu: String) => {
      val split: Array[String] = stu.split(",")
      val id: String = split(0)
      val name: String = split(1)
      val clazz: String = split(4)
      s"$id,$name,$clazz"
    })

    for (s <- stuList) {
      println(s)
    }

  }

}
